﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Customer_Profile.eCard.DBDao;
using KVB.Common;


namespace Customer_Profile.eCard
{
    public partial class reNew : System.Web.UI.Page
    {
        string dealno = "";
        public string cardno ="";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["dealno"] != null)
                dealno = Request["dealno"].ToString();

            if (!Page.IsPostBack)
            {

                DataSet dsoldDealInfo = DealDao.getMMDealsbyDealno(dealno);
                rptOldDealInfo.DataSource = dsoldDealInfo;
                rptOldDealInfo.DataBind();
                cardno= dsoldDealInfo.Tables[0].Rows[0]["card_no"].ToString();
                txtCardno.Value = cardno;

                Comm.BindDll(ref dropSaleEntity, "Entity", false, "");
                DataSet dsProd = ProductDao.getAllProduct("ALL");
                dropProd.DataSource = dsProd;
                dropProd.DataTextField = "procduct_name";
                dropProd.DataValueField = "procduct_code";
                dropProd.DataBind();

                dropProdAgain.DataSource = dsProd;
                dropProdAgain.DataTextField = "procduct_name";
                dropProdAgain.DataValueField = "procduct_code";
                dropProdAgain.DataBind();

                DataSet dsAgent = SaleAgentDao.getSaleAgentList("N");
                dropAgentName.DataSource = dsAgent;
                dropAgentName.DataTextField = "sale_agent_name";
                dropAgentName.DataValueField = "sale_agent_name";
                dropAgentName.DataBind();

                ListItem li = new ListItem("请选择", "");
                dropAgentName.Items.Insert(0, li);
            }
        }

        protected void btnDealSave_Click(object sender, EventArgs e)
        {
            string prod_code = dropProd.SelectedItem.Value;
            string deal_term = dropProdAgain.SelectedItem.Text.Split('|')[1].ToString(); //dropTerm.SelectedItem.Value;
            string card_no = txtCardno.Value;
            decimal real_count = decimal.Parse(txtRealAmount.Value);
            decimal real_discount = decimal.Parse(txtDiscount.Value);
            decimal incard_count = decimal.Parse(txtIncardAmount.Value);
            DateTime value_date = DateTime.Parse(txtValueDate.Value.ToString());
            DateTime due_date = DateTime.Parse(txtDueDate.Value.ToString());
            //decimal interest = decimal.Parse(txtAnnualInterest.Value);
            string if_agent = dropIfagain.SelectedItem.Value;
            string agent_name = dropAgentName.SelectedItem.Value;
            string remark = txtRemark.Value;

            string if_again = dropIfagain.SelectedItem.Value;
            string againPeriod = "";
            if (if_again.Equals("Y"))
                againPeriod = dropProdAgain.SelectedItem.Text.Split('|')[1].ToString();

            bool bok = DealDao.reNew(dealno, prod_code, deal_term, card_no, real_count, real_discount, incard_count, value_date, due_date, remark, if_again, againPeriod,if_agent,agent_name);
            if (bok)
                Response.Write("<script language=javascript>alert('success');</script>");
            else
                Response.Write("<script language=javascript>alert('error');</script>");
        }
    }
}